const fp = require("fastify-plugin");
const DataTypes = require("sequelize");

module.exports = fp(async function (fastify, options) {
  fastify.decorate("card", function () {
    var card = fastify.sequelize.define(
      "card",
      {
        id: {
          type: DataTypes.BIGINT,
          primaryKey: true,
          autoIncrement: true,
          allowNull: false,
        },
        status: { type: DataTypes.TINYINT, defaultValue: true },
        memberId: {
          type: DataTypes.STRING,
          defaultValue: false,
          field: "member_id",
        },
        cardNumber: { type: DataTypes.STRING, field: "card_number" },
        cardType: { type: DataTypes.STRING, field: "card_type" },
        bankCode: { type: DataTypes.STRING, field: "bank_code" },
        validated: { type: DataTypes.BOOLEAN, defaultValue: true },
      },
      { tableName: "card", timestamps: false }
    );
    // fastify.sequelize.sync({ force: true });
    return card;
  });
});
